package threadBaseUse;

/**
 * @description: 线程的插队和礼让方法测试
 * @author: Liuwanqing
 * @date: 2022-10-14 17:48
 */
public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        T3 thread = new T3();
        thread.start();

        // 实现主线程吃了 5 个包子后，让子线程全部吃完
        for (int i=0; i<20; i++){
            Thread.sleep(1000);
            System.out.println(" 主线程吃了" + i + "个包子");
            if(i == 5){
                System.out.println("主线程吃了 5 个包子后，让子线程全部吃完");
                // thread.join();
                Thread.yield();
            }
        }
    }
}

class T3 extends  Thread {
    @Override
    public void run() {
        for (int i=0; i<=20; i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(" 子线程吃了" + i + "个包子");
        }
    }
}


